﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhotoGallery.Model;
using PhotoGallery.DLL;
namespace PhotoGallery.BLL
{
    public class CommentAction
    {
        CommentDataAccess cda = new CommentDataAccess();
        /*添加评论*/
        public void addComent(string pid,string uid,string sid,string content) 
        {
            cda.insert(pid, uid, sid, content, "0", "0");
        }
        /*加入收藏
         *  图片原作者的id是sid
         * 当前用户的id的uid
         * 当前用户将图片收入收藏
         * sid是根据pid找到的
         * uid收藏了sid用户的图
         * sid用户将会收到消息
         */
        public void addFavor(string pid,string uid) 
        {
            PictureDataAccess pda = new PictureDataAccess();
            string sid=pda.searchpictureById(pid).Uid;
            cda.insert(pid, uid, sid, "", "0", "1");
        }
        /*取消收藏*/
        public void offFavor(string pid,string uid) 
        {
            cda.unFavor(pid, uid);
        }
        /*显示消息*/
        public List<Comment> commentList(string sid) 
        {
            return cda.searchCommentBySid(sid);
        }
        /*某一张图片下方的评论*/
        public List<Comment> commentofPic(string pid) 
        {
            return cda.searchCommentByPicId(pid);
        }
        /*删除评论*/
        public void delcomment(string cid) 
        {
            cda.delete(int.Parse(cid));
        }

        /*判断是否已收藏*/
        public bool isfavor(string pid, string uid)
        {
            List<Comment> list=cda.searchCommentByPidAndUid(pid, uid);
            if (list != null) 
            {
                foreach (Comment c in list) 
                {
                    if (c.State == "1") 
                    {
                        return true;
                    }
                }
                return false;
            } 
            else 
            { 
                return false; 
            }
        }
        /*取出我收藏的全部图片*/
        public List<Picture> getmyfavor(string uid) 
        {
            List<Picture> favorlist = cda.searchFavorPic(uid);
            return favorlist;
            
        }
    }
}
